package ase.eleitweg;

import java.util.*;

import ase.eleitweg.common.*;
import ase.eleitweg.server.*;
import ase.eleitweg.server.db.*;
import java.rmi.*;
import java.io.*;

import com.google.inject.Guice;
import com.google.inject.Injector;

import ase.eleitweg.client.gui.utils.*;

/**
 * Hello world!
 * 
 */
public class App {
	public static void main(String[] args) throws RemoteException {
		ELeitwegDAO dao = DatabaseFactory.getDB();
		dao.getAllWorkflows();
		Injector injector = Guice.createInjector(new LocalModule(), new TestDBFilledModule());
		RunManager rm = injector.getInstance(RunManager.class);
		UserManager um = injector.getInstance(UserManager.class);
		WorkflowManager wc = injector.getInstance(WorkflowManager.class);
		/*Workflow bauvorhaben = null;
		for(Workflow wf : wc.getWorkflows()) {
			if(wf.getName().equals("Bauvorhaben")) {
				bauvorhaben = wf;
			}
		}
		User berky = null;*/
		/*for(User u : um.getUsers()) {
			if(u.getUsername().equals("berky")) {
				berky = u;
			}
		}*/
		//System.out.println(bauvorhaben.getStartnode().getGroup().getUsers().get(0));
		//Run r = rm.createRun(bauvorhaben, bauvorhaben.getStartnode().getGroup().getUsers().get(0));
		System.out.println(rm.getAcceptableRuns(um.getUserById(184)).size());
		for(Run r : rm.getAcceptableRuns(um.getUserById(184))) {
			System.out.println(r.getUser().getEmail());
			System.out.println(r.isAccepted() + " " + r.getId());
			Document d = new Document(0, "bild.jpg", 0, r);
			File f = new File("C:\\bild.jpg");
			try {
				byte[] data = ase.eleitweg.client.gui.utils.FileByteConverter.fileToByte(f);
				d.setBinary(data);
				List<Document> docs = new Vector<Document>();
				docs.add(d);
				rm.uploadDocuments(r, docs);
			} catch (IOException e) {
				e.printStackTrace();
			}
			
		} 
	}
}
